var layer,guide;
layui.use(['layer'], function () {
    guide = {
        _initBtn: function(e,no){
                if(e){
                    $("#lc_img_left").append('<input type="button" class="layui-btn layui-btn-primary ml20 layui-btn-sm bold w80"\n' +
                        '                   badtNo=" '+no+' " value="指南" onclick="guide.events.showGuide(this)">');
                }
        },
        _initMileFileGuide: function(milefileSpans){
          if(milefileSpans && milefileSpans.length>0){
              $.each(milefileSpans,function(ind,e){
                  var milefileType = $(e).data('filetype');
                  if(milefileType){
                      var guideLenMap = guide.methods.getMilefileGuideLen(milefileType);
                      if(guideLenMap && guideLenMap.guideLen && (guideLenMap.guideLen*1)>0){
                          guide.methods.showMilefileGuide($(e),guideLenMap.badtNo);
                      }
                  }
              })
          }
        },
        events: {
            //指南点击事件:
            showGuide:function(e){
                //查看页面中是否已经加载,如果加载了,从页面中获取,如果没有加载访问后端获取
                var badtNo = $(e).attr('badtno');
                var w,h;
                if (w == null || w == '') {
                    w = ($(window).width() *0.92);
                }
                ;
                if (h == null || h == '') {
                    h = ($(window).height()-80);
                }
                layer.open({
                    type: 2,
                    title: '指南',
                    shadeClose: true,
                    shade: 0.8,
                    maxmin: false,
                    area: [w + 'px', h + 'px'],
                    content: '/adminManager/supervisor/milepostManager/getGuide?badtNo='+badtNo //iframe的url
                });
            }
        },
        methods: {
            getMilefileGuideLen: function(e){
                //查看某里程文件是否有指南内容：
                var returnData = {};
                $.ajax({
                    url: '/adminManager/supervisor/milepostManager/getMilefileGuideLen',
                    data: {mileFileType: e},
                    type: 'get',
                    cache: false,
                    async: false,
                    dataType: 'json',
                    success: function(res){
                        if(res.flag){
                            returnData = res.data;
                        }
                    },
                    error: function(res){

                    }
                })
                return returnData;
            },
            showMilefileGuide: function(e,badtNo){
                if(e){
                    $(e).append('<input type="button" class="layui-btn layui-btn-primary ml20 mt00 layui-btn-sm bold w80"\n' +
                        '                   badtNo=" '+badtNo+' " value="指南" onclick="guide.events.showGuide(this)">');
                }
            }
        }
    }
});